package solution.T0215_1_Clipboard.command;

import solution.T0215_1_Clipboard.Clipboard;

import java.util.function.Consumer;

public class PasteCommand extends Command {
    private final Integer copyId;
    private final Consumer<String> callback;

    public PasteCommand(Consumer<String> callback) {
        this.copyId = null;
        this.callback = callback;
    }

    public PasteCommand(Integer copyId, Consumer<String> callback) {
        this.copyId = copyId;
        this.callback = callback;
    }

    @Override
    public void execute() {
        Clipboard clipboard = Clipboard.getInstance();
        String pasteContent;

        if (copyId != null) {
            CopyCommand command = clipboard.getCommandById(copyId);
            pasteContent = (command != null) ? command.getContent() : "";
        } else {
            pasteContent = clipboard.getContent();
        }

        callback.accept(pasteContent); // Invoke the callback with the pasted content
    }
}
